//
//  XMPPClient.h
//  Gildata
//
//  Created by 陆惠国 on 11-8-8.
//  Copyright 2011年 恒生聚源. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "XMPPFramework.h"
#import "MessageModule.h"
#import "MessageCoreDataStorage.h"

@interface XMPPClient : NSObject<XMPPRosterDelegate>
{
    XMPPStream *_xmppStream;
    XMPPReconnect *_xmppReconnect;
	XMPPRoster *_xmppRoster;
    XMPPRosterCoreDataStorage *_xmppRosterStorage;
    XMPPvCardCoreDataStorage *_xmppvCardStorage;
    XMPPvCardAvatarModule *_xmppvCardAvatarModule;
    XMPPvCardTempModule *_xmppvCardTempModule;
    
    XMPPCapabilities *_xmppCapabilities;
	XMPPCapabilitiesCoreDataStorage *_xmppCapabilitiesStorage;
    
    MessageModule * _messageModule;
	MessageCoreDataStorage * _messageStorage;
	
	NSManagedObjectContext * _managedObjectContext_roster;
	NSManagedObjectContext * _managedObjectContext_capabilities;
    NSManagedObjectContext * _managedObjectContext_message;
    
    
    BOOL _allowSelfSignedCertificates;
	BOOL _allowSSLHostNameMismatch;
	BOOL _isXmppConnected;
    
    NSString* _password;
    UIImage *_defaultAvatar;
    NSDate* _lastLoginDate;
}

@property (nonatomic, readonly) XMPPStream *xmppStream;
@property (nonatomic, readonly) XMPPReconnect *xmppReconnect;
@property (nonatomic, readonly) XMPPRoster *xmppRoster;
@property (nonatomic, readonly) XMPPRosterCoreDataStorage *xmppRosterStorage;
@property (nonatomic, readonly) XMPPvCardTempModule *xmppvCardTempModule;
@property (nonatomic, readonly) XMPPvCardAvatarModule *xmppvCardAvatarModule;
@property (nonatomic, readonly) XMPPCapabilities *xmppCapabilities;
@property (nonatomic, readonly) XMPPCapabilitiesCoreDataStorage *xmppCapabilitiesStorage;

@property (nonatomic, readonly) MessageModule *messageModule;
@property (nonatomic, readonly) MessageCoreDataStorage *messageStorage;

@property (nonatomic, retain) UIImage *defaultAvatar;
@property (nonatomic, retain) NSDate* lastLoginDate;

+ (XMPPClient *)sharedInstance;

- (NSManagedObjectContext *)managedObjectContext_roster;
- (NSManagedObjectContext *)managedObjectContext_capabilities;
- (NSManagedObjectContext *)managedObjectContext_message;

- (BOOL)connect;
- (BOOL)connectWithJID:(NSString *)jid AndPassword:(NSString *)password;
- (void)disconnect;

- (void)clearAllMessages;
- (void)clearAllReadedMessages;
- (void)clearMessagesForJID:(XMPPJID *)jid;
- (void)saveAll;

- (XMPPUserCoreDataStorageObject *)userForJID:(XMPPJID *) jid;
- (XMPPUserCoreDataStorageObject *)myUser;

- (UIImage *)avatarForUser:(XMPPUserCoreDataStorageObject *) user;
- (UIImage *)avatarForJID:(XMPPJID *) jid;
- (UIImage *)myAvatar;

- (void)goOnline;
- (void)goOffline;
- (void)goAway;

@end


